var app=getApp();
let util=require("../../utils/util.js");
let latitude;
let longitude;

Page({
  data: {
    certifyUrl: "../images/certify.png",//已认证图片路径
    uncertifyUrl: "../images/uncertify.png",//未认证图片路径
    hotUrl:"../images/hot.png",//人气图片路径
    positionUrl:"../images/position.png",//距离图片路径
    distance: 5,//测试数据  距离
    followedUrl:"../images/followed.png",//已关注的图片路径
    unfollowUrl: "../images/unfollowed.png",//未关注的图片路径
    scrollLeft:0,
    greyshow:false,//是否显示弹出框 ture--显示 false--隐藏
    isHideLoadMore: true,
    //测试数据，导航分类
    navlist:[{
      id:1,
      name:"美妆护肤"
    },{
        id: 2,
        name: "营养保健"
    },{
        id: 3,
        name: "个人洗护"
      }, {
        id: 4,
        name: "母婴"
      }, {
        id: 5,
        name: "饰品"
      }, {
        id: 6,
        name: "运动补给"
      }, {
        id: 7,
        name: "鞋帽"
      }, {
        id: 8,
        name: "收纳用品"
      }],
    activeIndex: 0,
    followFlag:true,
    shoplist:[{
      shopid:1,
      xuhao:1,
      shoplogo:"../images/bang.png",
      shopname:"巴黎欧莱雅徐州总店",
      certify:true,
      cerbifyUrl: "../images/certify.png",
      hotNum: 1520,
      latitude:"35.0125",
      longitude:"117.35632",
      followFlag:true,
      picrul:[{
        url:"../images/pic0.png",
        price:"56"
      }, {
          url: "../images/pic0.png",
          price: "50"
        }, {
          url: "../images/pic0.png",
          price: "9.9"
        }
      ]
      },{
        shopid: 2,
        xuhao:2,
        shoplogo: "../images/bang.png",
        shopname: "巴黎欧莱雅徐州2店",
        certify: false,
        cerbifyUrl: "../images/uncertify.png",
        hotNum: 1500,
        latitude: "35.0125",
        longitude: "117.35632",
        followFlag: false,
        picrul: [{
          url: "../images/pic0.png",
          price: "56"
        }, {
          url: "../images/pic0.png",
          price: "30"
        }, {
          url: "../images/pic0.png",
          price: "9.9"
        }
        ]
      }, {
        shopid: 1,
        xuhao: 3,
        shoplogo: "../images/bang.png",
        shopname: "巴黎欧莱雅徐州总店",
        certify: true,
        cerbifyUrl: "../images/certify.png",
        hotNum: 1520,
        latitude: "35.0125",
        longitude: "117.35632",
        followFlag: true,
        picrul: [{
          url: "../images/pic0.png",
          price: "56"
        }, {
          url: "../images/pic0.png",
          price: "50"
        }, {
          url: "../images/pic0.png",
          price: "9.9"
        }
        ]
      }, {
        shopid: 2,
        xuhao: 4,
        shoplogo: "../images/bang.png",
        shopname: "巴黎欧莱雅徐州2店",
        certify: false,
        cerbifyUrl: "../images/uncertify.png",
        hotNum: 1500,
        latitude: "35.0125",
        longitude: "117.35632",
        followFlag: false,
        picrul: [{
          url: "../images/pic0.png",
          price: "56"
        }, {
          url: "../images/pic0.png",
          price: "30"
        }, {
          url: "../images/pic0.png",
          price: "9.9"
        }
        ]
      }]
      
  },
  onLoad: function () {
    var that=this;
      wx.getLocation({
        success: function(res) {
          console.log("--------------当前定位信息");
          console.log(res);
          latitude=res.latitude;
          longitude=res.longitude;
          that.setData({
            latitude:res.latitude,
            longitude:res.longitude
          })
        },
      })
  },
  choseNav:function(e){
    var that=this;
    var currentIndex=e.currentTarget.dataset.index;
    var offsetX=e.detail.x;
    if(offsetX<160){
      that.setData({
        scrollLeft:0
      })
    }else if(offsetX>320){
      that.setData({
        scrollLeft: offsetX - 50
      })
    }else{
      that.setData({
        scrollLeft: offsetX-50
      })
    }
    console.log(e);
    console.log(offsetX);
    that.setData({
      activeIndex:currentIndex,
      
    })
    //请求接口，获取数据
    that.loadingBoard();
  },
  //弹出面板选择标签
  choseNav2: function (e) {
    var that = this;
    var currentIndex = e.currentTarget.dataset.index;
    console.log(e);
    that.setData({
      activeIndex: currentIndex
    })
    that.choseNav(e);
   setTimeout(function(){
     that.setData({
       greyshow:false
     })
   },200)

  },

  //显示和隐藏加载中提示
  loadingBoard:function(){
      wx.showLoading({
        title: '正在加载中',
      })
      setTimeout(function () {
        wx.hideLoading()
       }, 500)

    
  },

  //打开弹出面板
  opengrey:function(){
    var that=this;
    that.setData({
       greyshow:true
    })
  },

  //关闭填出面板
  chosegrey:function(){
    var that = this;
    that.setData({
      greyshow:false
    })
  },

  /**************到达底部**********************/
  onReachBottom:function(e){
    var that = this;
      console.log("到达底部");
      console.log(that);
      
      // wx.showLoading({
      //   title: '正在加载中...',
      // })
     
      that.setData({
        isHideLoadMore: false
        
      })
      setTimeout(function(){
        that.setData({
          isHideLoadMore: true
        })
      },500)
  },



  /*********************/
 calcDistance:function(lonA, latA, lonB, latB) {
    var earthR = 6371000;
    var x = Math.cos(latA * Math.PI / 180.) * Math.cos(latB * Math.PI / 180.) * Math.cos((lonA - lonB) * Math.PI / 180);
    var y = Math.sin(latA * Math.PI / 180.) * Math.sin(latB * Math.PI / 180.);
    var s = x + y;
    if(s > 1) s = 1;
if (s < -1) s = -1;
var alpha = Math.acos(s);
var distance = (alpha * earthR / 1000).toFixed(2);
//		    console.log("*********"+distance+"*********")
return distance;
		}
  
})